/*
 * @Descripttion: file content
 * @Author: liuzhou
 * @Date: 2022-06-16 17:45:45
 * @LastEditors: liuzhou
 * @LastEditTime: 2022-06-17 13:58:19
 */
import fecha from 'fecha';

function getDays(ranges, IsHalfDay) {
  const day = !IsHalfDay ? 8.64e7 : 4.32e7;
  const days = new Set();
  for (const [start,end] of ranges) {
    for (let time = start; time <= end; time += day) {
      days.add(time);
    }
  }
  return !IsHalfDay ? days.size : days.size / 2;
}

function reGetMilliseconds(oriMilliseconds, IsHalfDay) {
  const hours = new Date(oriMilliseconds).getHours();
  const minutes = new Date(oriMilliseconds).getMinutes();
  const temp = IsHalfDay && (hours > 12 || (hours === 12 && minutes > 0)) ? 4.32e7 : 0
  return Date.parse(fecha.format(oriMilliseconds, 'YYYY-MM-DD')) + temp;
}

export default { reGetMilliseconds, getDays };